package com.xhji.web.mvc.autoconfig;

import com.xhji.web.mvc.response.DefaultResponseDecorate;
import com.xhji.web.mvc.response.ResponseDecorate;
import com.xhji.web.mvc.request.RestControllerExceptionHandler;
import com.xhji.web.mvc.interceptor.HandlerMethodLogInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

@Configuration
@ConditionalOnClass(ResponseBodyAdvice.class)
public class DecorateAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(ResponseDecorate.class)
    public ResponseDecorate responseDecorate() {
        return new DefaultResponseDecorate();
    }

    @Bean
    @ConditionalOnMissingBean
    public RestControllerExceptionHandler restControllerExceptionHandler() {
        return new RestControllerExceptionHandler();
    }

    @Bean
    public HandlerMethodLogInterceptor logInterceptor() {
        return new HandlerMethodLogInterceptor();
    }
}
